# Python 趣味编程：第 3 章
#    例題 3.1 Key 被按下时，显示 keysym
# --------------------------
# 程序名: 03-key-event.py

from tkinter import *
tk = Tk()
canvas = Canvas(tk, width=400, height=300)
canvas.pack()

# Key Event Handler
def on_key_press(event):
    # 显示字符
    print("key: {}".format(event.keysym))

# 将事件处理程序与事件关联起来
canvas.bind_all("<KeyPress>", on_key_press)
